﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FileStream的简单练习
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //FileStream fileStream = new FileStream(@"D:\test\config\config.txt", FileMode.OpenOrCreate, FileAccess.Read);
            //FileStream fileStream1 = new FileStream(@"D:\test\config\config.txt", FileMode.OpenOrCreate, FileAccess.Write);
            //FileStream fileStream2 = new FileStream(@"D:\test\config\config.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            ////这里不指认对文件能否进行读写，默认就是可读可写
            //FileStream fileStream3 = new FileStream(@"D:\test\config\config.txt", FileMode.OpenOrCreate);

            //using (FileStream fileStream = new FileStream(@"D:\test\config\config.txt", FileMode.OpenOrCreate, FileAccess.Read))
            //{
            //    int flag = 0;
            //    while(true)
            //    {
            //        flag = fileStream.ReadByte();
            //        if(flag == -1)
            //        {
            //            break;
            //        }
            //        Console.WriteLine($"{flag}: {(char)flag}");
            //    }
            //}

            //using (FileStream fileStream = new FileStream(@"D:\test\config\config.txt", FileMode.OpenOrCreate, FileAccess.Read))
            //{
            //    byte[] buffer = new byte[1024];//输入缓冲区

            //    int flag = 0;
            //    while (true)
            //    {
            //        flag = fileStream.Read(buffer, 0, buffer.Length);
            //        if (flag == 0)
            //        {
            //            break;
            //        }
            //        string s = Encoding.UTF8.GetString(buffer, 0, flag);
            //        Console.WriteLine(s);
            //    }
            //}

            using (FileStream fileStream = new FileStream(@"D:\test\config\config.txt", FileMode.Append, FileAccess.Write))
            {
                byte[] buffer = Encoding.UTF8.GetBytes("beauty"); //输出缓冲区
                fileStream.Write(buffer, 0, buffer.Length);
            }
        }
    }
}
